/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/


#if !defined(AFX_PGLEVENT_H__A25FCF19_DED1_4E24_85D2_AC67E640FCB4__INCLUDED_)
#define AFX_PGLEVENT_H__A25FCF19_DED1_4E24_85D2_AC67E640FCB4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <pgl/core/PGLRegion.h>
#include <pgl/igfx/GfxInterface.h>
#include <pgl/mfc/PGLMouse.h>

/*! 
	\defgroup EventHandlerGroup A mouse event handler
	\ingroup PGLMFCGroup
*/

//! Declaring an event  class
#define PGLMFC_DECLARE_EVENT( className, baseClass )\
	LPCTSTR GetClassName() const				{	return _T( #className );}; \
	bool IsKindOf(LPCTSTR szClassName) const	\
	{	\
		if (_tcscmp( GetClassName(), szClassName ) == 0) \
			return true;\
		else \
			return baseClass::IsKindOf( szClassName );\
	};

#define PGLMFC_RUNTIME_CLASS( className)	_T(#className)


/*! \brief Base class for event handler

  \ingroup EventHandlerGroup
*/
class PGLMFC_EXT_CLASS CPGLEvent  
{
public:

	CPGLEvent();
	virtual ~CPGLEvent();

	//! returns the class name
	virtual LPCTSTR GetClassName() const				{	return _T("CPGLEvent");};
	//! returns true if of the type szClassName
	virtual bool IsKindOf(LPCTSTR szClassName) const	{	return _tcscmp( GetClassName(), szClassName ) == 0;};
	//! returns true if all pointers are valid (non-null)
	bool IsValid() const;

	//! \name Setters and getters
	//@{
	//! Sets the pointer to the GDI+ interface
	void SetGfx( gfxinterface::CGDIpInterface* pGfx)			{	m_pGfx=pGfx;};
	//! returns the pointer to the GDI+ interace
	gfxinterface::CGDIpInterface* GetGfx()						{	return m_pGfx;};

	//! Sets the pointer to the region
	void SetRegion(long uRegionID);
	//! returns the current region
	CPGLRegionStPtr GetRegion()									{	return m_pRegion;};

	//! Sets the pointer to the parent window
	void SetParent( CWnd* pParent)								{	m_pParent = pParent;};
	///! returns the pointer to the parent window
	CWnd* GetParent()											{	return m_pParent;};

	//! Sets the pointer to the mouse object
	void SetMouse( CPGLMouse* pMouse)							{	m_pMouse = pMouse;};
	//! returns the pointer to the mouse object
	CPGLMouse* GetMouse()										{	return m_pMouse;};

	//! Sets the pointer to the GDI+ helper
	void SetHelper( gfxinterface::CGDIpHelper* pHelper)			{	m_pHelper = pHelper;};
	//! Returns the pointer to the GDI+ helper
	gfxinterface::CGDIpHelper* GetHelper()						{	return m_pHelper;};
	//@}

	//! \name Message Handlers
	//@{
	virtual void OnLButtonDown( UINT nFlags, CPoint point ){};
	virtual void OnLButtonUp( UINT nFlags, CPoint point ){};
	virtual void OnLButtonDblClk( UINT nFlags, CPoint point ){};

	virtual void OnMButtonDown( UINT nFlags, CPoint point ){};
	virtual void OnMButtonUp( UINT nFlags, CPoint point ){};
	virtual void OnMButtonDblClk( UINT nFlags, CPoint point ){};

	virtual void OnRButtonDown(UINT nFlags, CPoint point){}; 
	virtual void OnRButtonUp(UINT nFlags, CPoint point){};
	virtual void OnRButtonDblClk( UINT nFlags, CPoint point ){};

	virtual void OnMouseMove( UINT nFlags, CPoint point ){};
	virtual BOOL OnMouseWheel( UINT nFlags, short zDelta, CPoint pt ){	return FALSE;};

	virtual void OnHScroll( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar ){};
	virtual void OnVScroll( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar ){};

	virtual void OnKeyUp( UINT nChar, UINT nRepCnt, UINT nFlags ){};
	virtual void OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags ){};
	//@}

	//! Draw event related stuff
	virtual void Draw(Gdiplus::Graphics& graphics, const CRect& clientRect){};

private:
	gfxinterface::CGDIpInterface* m_pGfx;
	CPGLRegionStPtr m_pRegion;
	CWnd* m_pParent;
	CPGLMouse* m_pMouse;
	gfxinterface::CGDIpHelper* m_pHelper;
};

PGL_DECLARE_SMARTPTR( CPGLEvent );

class PGLMFC_EXT_CLASS CPGLPropEvent : public CPGLEvent  
{
public:
    virtual void OnRButtonDown(UINT nFlags, CPoint point);
};

PGL_DECLARE_SMARTPTR( CPGLPropEvent );

#endif // !defined(AFX_PGLEVENT_H__A25FCF19_DED1_4E24_85D2_AC67E640FCB4__INCLUDED_)
